home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_56 / stereo.inc < prev    next >
Text File  |  1995-01-01  |  9KB  |  246 lines

  1. _stereo_tick0:    cmp   [patterndelay],0
  2.                  je    _nodelay     ; or pattern delay done ...
  3.                  dec   [patterndelay]
  4.                  jz    _nodelay
  5.                  dec   [curline]
  6. _nodelay:        setborder 4
  7.                  call near ptr [READNEWNOTES]
  8.                  setborder 1
  9.                  jmp  _continuecalc
  10.  
  11. _anewtick:     mov           ax,[BPT]
  12.                mov           [TickBytesLeft],ax
  13.                mov           [calleffects],1
  14.                cmp           [curtick],1
  15.                jbe           _stereo_tick0
  16.                dec           [curtick]
  17.                jmp           _continuecalc
  18.  
  19. calc_stereo_tick PROC NEAR
  20.                push          bp
  21.                ; first fill tickbuffer with ZERO = 2048+offset post8bit
  22.                ; for 16bit play then ofcourse a bit different value ...
  23.                ; just only for 8bit play mode
  24.                mov           ax,word ptr [offset tickbuffer +2]
  25.                mov           es,ax
  26.                mov           ax,2048+offset post8bit
  27.                xor           di,di
  28.                mov           cx,[DMArealBufsize+2]
  29.                setborder     3
  30.                rep stosw
  31.                setborder     1
  32.                mov           [nextPosition],0
  33.                mov           [calleffects],0
  34.                cmp           [TickBytesLeft],0
  35.                jz            _anewtick
  36. _continuecalc:
  37.                mov           ax,word ptr [offset tickbuffer +2]
  38.                mov           es,ax 
  39.                cmp           [EndOfSong],1
  40.                je            _afterall
  41.                mov           al,[usedchannels]
  42.                mov           [curchannel],al
  43.                ; number of ticks we calc for every tick :
  44.                mov           ax,[TickBytesLeft]
  45.                shl           ax,1
  46.                mov           cx,[DMArealBufsize+2]
  47.                sub           cx,[nextPosition]
  48.                cmp           cx,ax
  49.                jbe           _cantfinishtick
  50.                mov           cx,ax     ; finish that Tick and loop to fill the whole tickbuffer
  51. _cantfinishtick:
  52.                mov           [sample2calc],cx
  53.                cmp           cx,0
  54.                je            _afterall
  55.  
  56.                xor           bp,bp
  57. _chnLoop:      cmp           ds:[channel.channeltyp+bp],0
  58.                je            _nextchannel
  59.                cmp           ds:[channel.channeltyp+bp],2
  60.                ja            _nextchannel
  61.                cmp           [calleffects],0
  62.                je            _noeff
  63.                ; do effects for this channel :
  64.  
  65.                mov           al,[curtick]
  66.                cmp           al,[curspeed]
  67.                je            _noeff_forfirst
  68. _doeff:        mov           bx,ds:[channel.command+bp]
  69.                cmp           bx,2*255
  70.                je            _noeff
  71.                call          [effects + bx]
  72. _noeff:
  73. _noeff_forfirst:
  74.                ; check if mixing :
  75.                cmp           ds:[channel.enabled+bp],0
  76.                je            _nextchannel
  77.  
  78.                mov           ax,ds:[channel.SampleSEG+bp]
  79.  
  80.                ; well now check if in EMS :
  81.                cmp           ax,0f000h
  82.                jb            _noEMSsample
  83.  
  84.                mov           edi,ds:[channel.sCurpos+bp]   ; load it for EMS optim.
  85.                rol           edi,16
  86.  
  87.                mov           si,ds:[channel.sLoopend+bp]
  88.  
  89.                and           ax,0fffh
  90.                mov           bx,ax
  91.                mov           ax,04400h
  92.                mov           dx,[smpEMShandle]  ; dx = handle
  93.                ; EMS access optimization (switch on only pages we really need !)
  94. EMSoptim2:     cmp           di,16*1024
  95.                jb            EMSoptim1
  96.                setborder 9
  97.                sub           di,16*1024
  98.                sub           si,16*1024
  99.                inc           bx
  100.                inc           al                         ; don't need this page !
  101.                jmp           EMSoptim2
  102. EMSoptim1:     mov           cx,1
  103.                cmp           di,16*1024-2*1024
  104.                jb            _onemorepage
  105.                cmp           si,16*1026
  106.                jbe           _onemorepage
  107.                inc           cx                         ; need two pages ...
  108. _onemorepage:  push          bp bx ax dx cx
  109.                ; Set page number:
  110.                int           67h
  111.                cmp           ah,0
  112.                je            _noEMSprob
  113.                mov           dl,0
  114.                div           dl         ; <- cause a "div by 0", if EMSdriver does not work correct
  115. _noEMSprob:    pop           cx dx ax bx bp
  116.                inc           al
  117.                inc           bx
  118.                dec           cx
  119.                jnz           _onemorepage
  120.                mov           ax,[frameseg]
  121.                setborder 1
  122. _noEMSsample:  mov           gs,ax
  123.  
  124.                lfs           si,[volumetableptr]
  125.  
  126.                mov           edi,ds:[channel.sCurpos+bp]   ; need to load this before EMS handling ...
  127.                rol           edi,16
  128.  
  129.                mov           edx,ds:[channel.sStep+bp]
  130.                rol           edx,16
  131.  
  132.                xor           ebx,ebx
  133.                mov           bh,ds:[channel.SampleVol+bp]
  134.  
  135.                mov           si,[nextPosition]
  136.                shl           si,1
  137.                mov           cx,[sample2calc]
  138.                shr           cx,1               ; stereo :)
  139.  
  140.                ; ES:SI - pointer to tickbuffer
  141.                ; GS:DI - pointer to sampledata
  142.                ; FS:BX - pointer to volumetable
  143.                ; DX    - decision part of current position in sample
  144.                ; DI    - integer part of current position in sample
  145.                ; BH    - volume of instrument
  146.                ; CX    - number of values to calc
  147.                ; DS,BP - under use, but not in inner loop <- not optimized (hey come on, I just started to code this)
  148.  
  149.                ; first check for correct position inside sample
  150.  
  151.                
  152.  
  153.                ; oh well - now stereo position
  154.                cmp           ds:[channel.channeltyp+bp],1
  155.                je            _leftside
  156.                add           si,2
  157. _leftside:
  158.  
  159.                ; jump into innerloop :
  160.                push          bp
  161.                mov           bp,cx
  162.                and           bp,31
  163.                shr           cx,5
  164.                inc           cx
  165.  
  166.                neg           bp
  167.                add           bp,32
  168.  
  169.                cmp           bp,32  ; <- that cost me some minutes to think about :(
  170.                jne           _no0
  171.  
  172.                dec           cx
  173.                xor           bp,bp
  174.  
  175. _no0:          shl           bp,1
  176.                sub           si,bp
  177.                sub           si,bp
  178.  
  179.                add           bp,offset st_innerloop_tbl
  180.  
  181.                ; before jump arround =) swap fs,ds
  182.                push         ds fs
  183.                mov          ax,ds
  184.                mov          fs,ax
  185.                pop          ds
  186.                push         ds
  187.  
  188.                jmp          word ptr fs:[bp]
  189.  
  190. macro_stinner  MACRO no
  191. st_inner&no:   mov           bl,gs:[di]         ; byte out of the sample
  192.  
  193.                add           edi,edx            ; next position in sample
  194.                adc           di,0               ; <- I need this !!
  195.  
  196.                mov           ax,ds:[ebx+ebx]    ; convert samplevalue with volumetable
  197.  
  198.                add           es:[si+pos],ax     ; mix value to other channels
  199. ENDM
  200.  
  201. _tickloop:
  202. z = 0
  203. pos = 0
  204. rept 32        ; I know I'm crazy :) but what we do for fast inner loops ...
  205. macro_stinner %z
  206. pos = pos + 4
  207. z = z + 1
  208. endm
  209.                add           si,32*4
  210.                dec           cx
  211.                jnz           _tickloop
  212.                pop           fs
  213.                pop           ds
  214.                pop           bp
  215.  
  216. _aftercalc:    cmp           di,ds:[channel.sLoopend+bp]
  217.                jae           _sampleends
  218. _back2main:    rol           edi,16
  219.                mov           dword ptr ds:[channel.sCurpos+bp],edi
  220.  
  221. _nextchannel:  add           bp,size channel
  222.                dec           [curchannel]
  223.                jnz           _chnLoop
  224.  
  225.                mov           ax,[sample2calc]
  226.                add           [nextPosition],ax
  227.                shr           ax,1
  228.                sub           [TickBytesLeft],ax
  229.                mov           ax,[DMArealBufsize+2]
  230.                cmp           [nextPosition],ax
  231.                jb            _anewtick
  232.  
  233. _afterall:     pop           bp
  234.                ret
  235.  
  236. _sampleends:   cmp           ds:[channel.sloopflag+bp],0
  237.                je            _no_loopflag
  238. _tryagain:     sub           di,ds:[channel.sloopEnd+bp]
  239.                add           di,ds:[channel.sloopstart+bp]
  240.                cmp           di,ds:[channel.sloopEnd+bp]
  241.                jae           _tryagain
  242.                jmp           _back2main
  243. _no_loopflag:  mov           ds:[channel.enabled+bp],0
  244.                jmp           _back2main
  245.  
  246. calc_stereo_tick ENDP